﻿using System;
using System.IO;

namespace maimg.barcode
{
    using maimg.helpers;
    using ZXing.Common;
    using ZXing.Datamatrix;

    public class DataMatrix
    {
        internal static BitMatrix read(string content, int w)
        {
            var writer = new DataMatrixWriter();
            var a = writer.encode(content, ZXing.BarcodeFormat.DATA_MATRIX, 120, 18);
            return a;
        }
        public static Stream make(string content, int w = 4)
        {
            var a = read(content, w);

            return helper.download_bmp(a, w);
        }
        public static Stream make_png(string content, int w = 4)
        {
            var a = read(content, w);

            return helper.download_png(a, w);
        }
        public static Stream make(string content, string fontpath, int w = 4)
        {
            var a = read(content, w);
            var g = helper.convert_grid(a, w);
            g = helper.grid_add_text(g, content, fontpath);

            return helper.download_bmp(g);
        }
    }
}
